package com.googlecode.jmicroerp.security;

import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.security.authentication.event.AuthenticationFailureBadCredentialsEvent;
import org.springframework.security.authentication.event.AuthenticationSuccessEvent;
import org.springframework.stereotype.Component;

/**
 *
 * @author alex
 */
@Component
public class SecurityEventListener implements ApplicationListener<ApplicationEvent> {

    @Override
    public void onApplicationEvent(ApplicationEvent event) {
        if (event instanceof AuthenticationFailureBadCredentialsEvent) {
            AuthenticationFailureBadCredentialsEvent failedAuth = (AuthenticationFailureBadCredentialsEvent) event;
            Object principal = failedAuth.getAuthentication().getPrincipal();
            
        } else if (event instanceof AuthenticationSuccessEvent) {
            AuthenticationSuccessEvent successAuth = (AuthenticationSuccessEvent) event;
            Object principal = successAuth.getAuthentication().getPrincipal();
            
        }
    }
}
